import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.Field

//global variable
@Field String GITURL = "https://git.devopsing.com.cn"

def sendGetRequest(String apiUrl)
{
    //def connection = new URL("https://git.devopsing.com.cn/api/v4/users/1696").openConnection() as HttpURLConnection

    def connection = new URL("${GITURL}/${apiUrl}").openConnection() as HttpURLConnection
    //必须是GET方法
    connection.setRequestMethod("GET")
    connection.setRequestProperty('User-Agent', 'groovy-'.concat(GroovySystem.getVersion()))
    connection.setRequestProperty('Accept', 'application/json')
    //必须设置PRIVATE-TOKEN，不然返回404状态
    connection.setRequestProperty('PRIVATE-TOKEN', '1qfBxwCzmLRknsuFZQXs')
    def response = connection.inputStream.text
//    println(response.toString())
    return response
}

def jsonHandler(String value)
{
    //json处理
    def slurper = new JsonSlurper()
    def jsonText = slurper.parseText(JsonOutput.prettyPrint(value.toString()))
    def email=jsonText.name as String[]
    for(String i in email) {
        println(i);
    }
//println(email.toString())

}

def call(String apiUrl)
{
    def result= sendGetRequest (apiUrl)
    jsonHandler(result)
}

call("/api/v4/groups/smartconstruction/members")






